package com.cangsan.erhai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cangsan.erhai.entity.SysMenu;
import com.cangsan.erhai.entity.SysRoleMenu;
import com.cangsan.erhai.mapper.SysMenuMapper;
import com.cangsan.erhai.mapper.SysRoleMenuMapper;
import com.cangsan.erhai.service.SysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 76118
* @description 针对表【sys_role_menu(角色和菜单关联表)】的数据库操作Service实现
* @createDate 2024-09-17 16:13:26
*/
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu>
    implements SysRoleMenuService{


    @Autowired
    SysMenuMapper sysMenuMapper;

    @Override
    public Map<String, List<SysMenu>> getMenuByRoleId(Long roleId) {

        QueryWrapper<SysMenu> inget = Wrappers.<SysMenu>query().inSql("menu_id", "select menu_id from sys_role_menu where role_id=" + roleId);
        inget.select("menu_id","menu_name");
        inget.eq("is_del",0);
        List<SysMenu> inMenu = sysMenuMapper.selectList(inget);
        QueryWrapper<SysMenu> notIn = Wrappers.<SysMenu>query().notInSql("menu_id", "select menu_id from sys_role_menu where role_id=" + roleId);
        notIn.select("menu_id","menu_name");
        notIn.eq("is_del",0);
        List<SysMenu> notMenu = sysMenuMapper.selectList(notIn);
        Map<String, List<SysMenu>>  res = new HashMap();
        res.put("inMenu",inMenu);
        res.put("notMenu",notMenu);
        return res;
    }
}




